package com.topone.controller;


import com.topone.Utils.ResultVOUntil;
import com.topone.VO.ResultVO;
import com.topone.service.BussinessService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;
import java.util.Objects;


@RestController
@RequestMapping("/seller/balance")
@Slf4j
@CrossOrigin
public class BalanceController {

    @Autowired
    private BussinessService bussinessService;

    @GetMapping("/find")
    public ResultVO getBalance(@RequestParam(value = "bussinessId") String bussinessId,
                               @RequestParam(value = "bussinessCode") String bussinessCode,
                               @RequestParam(value = "flag",required = false) String flag) {

        Map<String, Object> map ;
        if(StringUtils.equals("balance",flag)){
           map= bussinessService.bussinessBalance(bussinessId, bussinessCode,flag);
        }else {
             map = bussinessService.bussinessBalance(bussinessId, bussinessCode,null);
        }

        if (Objects.nonNull(map)) {
            log.debug("结算结果:{}", map);
            return ResultVOUntil.success(map);
        } else {
            log.debug("无结算商家信息");
            return ResultVOUntil.error(1, "无结算商家信息");
        }
    }
}
